package com.jkd.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jkd.mapper.RoomMapper;
import com.jkd.model.pojo.Room;
import com.jkd.model.vo.RoomQueryVo;
import com.jkd.service.IRoomService;
import com.jkd.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RoomServiceImpl implements IRoomService {
    @Override
    public PageInfo<Room> selectByAll(RoomQueryVo roomQueryVo, Integer pageNum, Integer pageSize) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
       RoomMapper roomMapper  = sqlSession.getMapper(RoomMapper.class);
        PageHelper.startPage(pageNum,pageSize);
        List<Room> list = roomMapper.selectByCondition(roomQueryVo);
        PageInfo<Room> pageInfo = new PageInfo<>(list);
        MyBatisUtil.closeSqlSession(sqlSession);
        return pageInfo;
    }

    @Override
    public List<String> selectByDistinctRoom() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        RoomMapper roomMapper  = sqlSession.getMapper(RoomMapper.class);
        List<String> list = roomMapper.selectDistinctRoom();
        MyBatisUtil.closeSqlSession(sqlSession);
        return list;

    }

    @Override
    public List<Integer> selectByDistinctCapacity() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        RoomMapper roomMapper  = sqlSession.getMapper(RoomMapper.class);
        List<Integer> list = roomMapper.selectDistinctCapacity();
        MyBatisUtil.closeSqlSession(sqlSession);
        return list;
    }

    @Override
    public Room selectById(Integer roomId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        RoomMapper roomMapper  = sqlSession.getMapper(RoomMapper.class);
        Room room = roomMapper.selectById(roomId);
        MyBatisUtil.closeSqlSession(sqlSession);
        return room;
    }

}
